<?php if($this->session->userdata('logged_in')) : ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>.: BooMS v1.1 :.</title>
<link type="text/css" rel="stylesheet" href="<?php echo base_url(); ?>/css/reset.css" />
<link type="text/css" rel="stylesheet" href="<?php echo base_url(); ?>/css/960.css" />
<link type="text/css" rel="stylesheet" href="<?php echo base_url(); ?>/css/main.css" />
<link type="text/css" rel="stylesheet" href="<?php echo base_url(); ?>/css/datepicker.css" />
<script type="text/javascript" src="<?php echo base_url(); ?>/js/jquery-1.6.1.min.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>/js/jquery-ui-1.8.9.custom.min.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>/js/datepicker.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>/js/jquery.qtip-1.0.0-rc3.min.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>/js/tinymce/jscripts/tiny_mce/jquery.tinymce.js"></script>
</head>
<?php //echo ($currentCategory);?>
<body>
<form id="frm" name="frm" action="" method="post">   
<input type="hidden" id="data" name="data" value="" />
<input type="hidden" id="action" name="action" value="" />
<div id="wrap">
	<div id="top">
        <div id="globalNavigation">
        	<div id="user">
            	<ul>
                	<li><a href="#">Change info</a></li>
                    <li><a href="<?php echo site_url().'/gafs/logout'; ?>">Log out</a></li>
                </ul>
            </div>
        	<div id="logo">
            	<h1>BooMS</h1>
                <p class="title"><em>Boo's website content management</em></p>
            </div>
        	<div id="menu">
                <ul>
                    <li class="selected"><a href="<?php echo site_url().'/product/'?>">Product</a></li>
                    <li><a href="<?php echo site_url().'/brand/'?>">Brand</a></li>
                    <li><a href="<?php echo site_url().'/advertisment/'?>">Advertiment</a></li>
                    <li><a href="#"></a></li>
                </ul>
            </div>
            <div class="clear"></div>
        </div>
    </div>
    <div id="middle">
    	<div id="middleWrap" class="container_24">
        	<h1>Product Management</h1>
            
            <div id="products" class="gridType">
            	<div id="gridHeader">
	                <div class="grid_1">&nbsp;</div>
                    <div class="grid_1">Copy</div>
                    <div class="grid_1">ID</div>
                    <div class="grid_4">Name</div>
                    <div class="grid_3">Category</div>
                    <div class="grid_3">Brand</div>
                    <div class="grid_2">Material</div>
                    <div class="grid_2">Size</div>
                    <div class="grid_2">Color</div>
                    <div class="grid_1">Show</div>
                    <div class="grid_1">Hot</div>
                    <div class="grid_1">Home</div>
                    <div class="grid_2">Sale</div>                 
                    <div class="clear"></div>
    			</div>
                <div class="gridBody">
                <?php foreach ($products as $key => $product): 
                    $rowClass = ($key % 2 == 0) ? 'evenRow' : 'oddRow';
                    $imgAccept = '<img src="'. base_url() .'/images/accept.png" alt="yes" class="status"';
                    $imgCancel = '<img src="'. base_url() .'/images/cancel.png" alt="no" class="status"';
                    $pShow = ($product->status == '1') ? $imgAccept.' id="status-0-'. $product->p_id .'" />' : $imgCancel.' id="status-1-'. $product->p_id .'" />';
                    $pHot = ($product->is_hot == '1') ? $imgAccept.' id="is_hot-0-'. $product->p_id .'" />' : $imgCancel.' id="is_hot-1-'. $product->p_id .'" />';
                    $pHome = ($product->is_home == '1') ? $imgAccept.' id="is_home-0-'. $product->p_id .'" />' : $imgCancel.' id="is_home-1-'. $product->p_id .'" />';
                    $pSale = ($product->is_sale == '1') ? $imgAccept.' id="is_sale-0-'. $product->p_id .'" />' : $imgCancel.' id="is_sale-1-'. $product->p_id .'" />';
                    $pSale .= ($product->sale_type == 'percent') ? $product->sale_value." %" : $product->sale_value." VND";
                ?>
                    <div class="gridItem <?php echo $rowClass; ?>">
                        <div class="grid_1">
                            <input type="checkbox" value="1" name="selectedBox[]">
                        </div>
                        <div class="grid_1">
                            <a class="btnCopy" href="<?php echo site_url()."/product/copy/".$product->p_id; ?>" alt="Copy" /></a>
                        </div>
                        <div class="grid_1"><a id="product_<?php echo $product->p_id; ?>" href="<?php echo site_url()."/product/update/".$product->p_id; ?>"><?php echo $product->p_id; ?></a></div>
                        <div class="grid_4"><a id="product_<?php echo $product->p_id; ?>" href="<?php echo site_url()."/product/update/".$product->p_id; ?>"><?php echo $product->p_name; ?></a></div>
                        <div class="grid_3"><a href="#"><?php echo $categoriesArray[$product->pcat_code]; ?></a>&nbsp;</div>
                        <div class="grid_3">
                            <a href="#">
                            <?php
                                if(array_key_exists($product->brandcode,$brandsArray)){
                                    echo $brandsArray[$product->brandcode];
                                            
                                } else {
                                    echo $product->brandcode;
                                }
                            ?>
                            </a>&nbsp;
                        </div>
                        <div class="grid_2"><?php echo $product->material; ?>&nbsp;</div>
                        <div class="grid_2"><?php echo $product->size; ?>&nbsp;</div>
                        <div class="grid_2"><?php echo $product->color; ?>&nbsp;</div>
                        <div class="grid_1"><?php echo $pShow; ?></div>
                        <div class="grid_1"><?php echo $pHot; ?></div>
                        <div class="grid_1"><?php echo $pHome; ?></div>  
                        <div class="grid_2 sale"><?php echo $pSale; ?></div>                               
	                    <div class="clear"></div>
                	</div>
                    <script>
                        $("#product_<?php echo $product->p_id; ?>").qtip({
                            content: {url: '<?php echo site_url(); ?>/welcome/index/<?php echo $product->p_id; ?>'},
                            fixed: false,
                            style: {
                                name: 'cream',
                                tip: {corner:'topLeft',color:'#39C',size:{x:10,y:10}},
                                border: {width:3, radius:6, color:'#39C'}
                            }
                        });
                    </script>
                <?php endforeach; ?>
           		</div>
            </div>
            
            <div class="actionBar product">
            	<div id="gridHeader">
	                <div class="grid_1">&nbsp;</div>
                    <div class="grid_1">Copy</div>
                    <div class="grid_5">Name</div>
                    <div class="grid_3">Category</div>
                    <div class="grid_3">Brand</div>
                    <div class="grid_2">Material</div>
                    <div class="grid_2">Size</div>
                    <div class="grid_2">Color</div>
                    <div class="grid_1">Show</div>
                    <div class="grid_1">Hot</div>
                    <div class="grid_1">Home</div>
                    <div class="grid_1">Sale</div>                 
                    <div class="clear"></div>
    			</div>
                <div id="filterBar">
                	<div class="grid_2">Filter by:</div>
                    <div class="grid_3">Category</div>
                    <div class="grid_5">Brand</div>
                    <div class="grid_4">Material</div>
                    <div class="clear"></div>
                    <div class="grid_5">
                    	<select id="filterCategory" name="filterCategory">
                        <!-- 
                        -- option's value will be fixed as product category code 
                        -- pcat_code & pcat_name are in product_category table.
                        -- Male or Memale can be retrieve in the first segment
                        -- of pcat_code
                        -------------------------------------------------------->
                            <option value="all">Tất cả</option>
                            <?php
                                foreach ($categoryGroups as $catGroupCode => $catGroupName) :
                                    $codeName = 'categories'.$catGroupCode;
                            ?>
                            <optgroup label="<?php echo $catGroupName; ?>">
                                <?php foreach($$codeName as $category) : ?>    
                                    <option value="<?php echo $category->pcat_code; ?>" <?php if ($category->pcat_code == $current_pcat_code) {echo 'selected="selected"';} ?>>
                                        <?php echo $category->pcat_name; ?>
                                    </option> 
                                <?php endforeach; ?>
                            </optgroup>
                            <?php endforeach; ?>
                        </select>
                    </div>
                    <div class="grid_5">
                    	<select id="filterBrand" name="filterBrand">
                        <!-- 
                        -- option's value will be fixed as product Brand 
                        -- brand_code & brand_name are in product_category table.
                        -- these values below are only for demo
                        -------------------------------------------------------->
                            <option value="all">Tất cả</option>
                            <?php foreach($brands as $brand) : ?>
                            <option value="<?php echo $brand->brand_alias; ?>" <?php if ($brand->brand_alias == $current_brandcode) {echo 'selected="selected"';} ?>>
                                <?php echo $brand->brand_name; ?>
                            </option>
                            <?php endforeach; ?>
                        </select>
                    </div>
                    <div class="grid_4">
                    	<select id="filterMaterial" name="filterMaterial">
                        <!-- 
                        -- option's value will be fixed as product Brand 
                        -- brand_code & brand_name are in product_category table.
                        -- these values below are only for demo
                        -------------------------------------------------------->
                            <option value="all">Tất cả</option>
                            <?php foreach($materials as $material) : ?>
                            <option value="<?php echo $material->material; ?>" <?php if ($material->material == $current_material) {echo 'selected="selected"';} ?>>
                                <?php echo $material->material; ?>
                            </option>
                            <?php endforeach; ?>
                        </select>
                    </div>
                    <div class="grid_1">
                        <input type="text" id="searchID" name="searchID" class="small" style="width:30px;" value="<?php if(isset($current_p_id)) {echo $current_p_id;} ?>" />
                        
                    </div>
                    <div class="grid_7">
                        <input type="text" id="searchName" name="searchName" class="large" style="width:300px;" value="<?php if(isset($current_p_name)) {echo $current_p_name;} ?>" />
                        
                    </div>
                    <div class="grid_1 actionMenu">
                        <ul>
                            <li><a href="#" id="filterSubmit">Go</a></li>
                        </ul>
                    </div>
                    <div class="clear"></div>
	            </div>
            	<div class="actionMenu grid_19">
                    <ul>
                        <li><a id="showAll" href="#">Show All</a></li>
                        <li><a href="<?php echo site_url(); ?>/product/add">Add</a></li>
                        <li><a href="#">Delete</a></li>
                        <li><a href="#">Advance Search</a></li>
                        <li><a href="#">Reset Sale</a></li>
                    </ul>
                </div>
                <div class="pagination grid_5">
                    <?php echo $pagination; ?>
                </div>
                <div class="clear"></div>
            </div>
        </div>
    </div>
    <div id="bottom">
    	<div class="threeCol"></div>
        <div class="threeCol"></div>
        <div class="threeCol"></div>
        <div class="clear"></div>
    </div>
</div>
</form>
<script type="text/javascript">
    $("img.status").click(function(){
        if($(this).attr('alt') == "yes" ){
            $("#statusData").val('0');
        } else {
            $("#statusData").val('1');
        }
        $("#data").val($(this).attr('id'));
        $("#frm").attr('action','<?php echo site_url(); ?>/product/update_status/<?php echo $offset; ?>');
        $("#frm").submit();
    });
    $("#filterSubmit").click(function(){
        $("#frm").attr('action','<?php echo site_url(); ?>/product/index');
        $("#frm").submit();
    })
    $("#showAll").click(function(){
        $("#action").val('showAll');
        $("#frm").attr('action','<?php echo site_url(); ?>/product/index');
        $("#frm").submit();
    });
    
    $('#filterCategory,#filterBrand,#filterMaterial,#searchID,#searchName').keypress(function(e){
		if (( e.which == 13 ) || (e.keycode==13))
		{
			$('#filterSubmit').click();
		}
	});

</script>    
</body>    
</html>
<?php else : redirect('gafs/index/'); ?>

<?php endif; ?>